//
//  BaseViewController.swift
//  Exchange
//
//  Created by rui on 2018/4/18.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {
    
    private(set) var titleLabel: UILabel?
    var customTitle: String? {
        set {
            if let title = self.titleLabel {
                title.text = newValue
            }else {
                let lbl = UILabel()
                lbl.themeTextColor = ThemeManager.ThemeColorKeys.text1
                lbl.font = UIFont.systemFont(ofSize: 30)
                lbl.textAlignment = .left
                lbl.frame = CGRect(x: 16, y: 0, width: self.view.frame.size.width, height: 78)
                titleLabel = lbl
                lbl.backgroundColor = UIColor.clear
                lbl.text = newValue
                self.view.addSubview(lbl)
            }
        }
        get {
            return titleLabel?.text
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        view.themeBackground = ThemeManager.ThemeColorKeys.background
        self.navigationController?.navigationBar.isTranslucent = false
        setNaviTheme()
        NotificationCenter.default.addObserver(self, selector: #selector(setNaviTheme), name: NSNotification.Name.Theme.ThemeNeedChange, object: nil)
    }
    
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        setStatusBarStyle()
    }
    
    func setComonNavigationBar()  {
        UIApplication.shared.statusBarStyle = .default
        self.navigationController?.navigationBar.barTintColor = UIColor.white
        self.navigationController?.navigationBar.tintColor = kThemeColor
        self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor : kTextColor]
    }
    
    func setBlackNavigationBar()  {
        self.navigationController?.navigationBar.barTintColor = kTitleColor
        
        self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white]
        UIApplication.shared.statusBarStyle = .lightContent
    }
    
    ///设置状态栏
    func setStatusBarStyle() {
        if ThemeManager.default.currentThemeMode() == .day {
           UIApplication.shared.statusBarStyle = .default
        }else {
            UIApplication.shared.statusBarStyle = .lightContent
        }
    }
    
    @objc func setNaviTheme() {
        guard let navi = self.navigationController else {return}
        navi.defaultTheme()
    }
    
}




